import java.util.ArrayList;
import java.util.List;

public class Subject implements ISubject{
    private List<Observer> observers = new ArrayList<Observer>();
    private String state;
    @Override
    public void attach(Observer observer) {
        observers.add(observer);
    }
    @Override
    public void detach(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyChange() {
        for (Observer observer : observers) {
            observer.update();
        }
    }
    @Override
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
        this.notifyChange();
    }
}
